package com.rc.saas.mini.service.elec;

import com.rc.saas.mini.common.config.UpYunConfig;
import com.rc.saas.mini.mapper.elec.ElecStationOutMapper;
import com.rc.saas.mini.model.elec.ElecStationOut;
import com.rc.saas.mini.model.elec.ElecStationOutExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ElecStationOutServiceImpl implements ElecStationOutService {

    @Autowired
    private UpYunConfig upYunConfig;

    @Autowired
    private ElecStationOutMapper elecStationOutMapper;

    @Override
    public ElecStationOutMapper getMapper() {
        return elecStationOutMapper;
    }

    @Override
    public ElecStationOut selectByStationId(Long stationId, String tenantCode) {
        ElecStationOutExample elecStationOutExample = new ElecStationOutExample();
        elecStationOutExample.createCriteria().andElecStationIdEqualTo(stationId).andTenantCodeEqualTo(tenantCode);
        List<ElecStationOut> elecStationOuts = elecStationOutMapper.selectByExample(elecStationOutExample);
        if (elecStationOuts != null && elecStationOuts.size() > 0) {
            //补全图片地址
            for (ElecStationOut elecStationOut : elecStationOuts) {
                elecStationOut.setOutImage1(elecStationOut.getOutImage1() != null ? upYunConfig.getDownloadRoot() + elecStationOut.getOutImage1() : "");
                elecStationOut.setOutImage2(elecStationOut.getOutImage2() != null ? upYunConfig.getDownloadRoot() + elecStationOut.getOutImage2() : "");
                elecStationOut.setOutImage3(elecStationOut.getOutImage3() != null ? upYunConfig.getDownloadRoot() + elecStationOut.getOutImage3() : "");
            }
            return elecStationOuts.get(0);
        } else {
            return null;
        }
    }

    @Override
    public ElecStationOut selectElecStationOutByElecStationId(Long stationId) {
        ElecStationOutExample elecStationOutExample = new ElecStationOutExample();
        elecStationOutExample.createCriteria().andElecStationIdEqualTo(stationId);
        List <ElecStationOut> elecStationOuts = elecStationOutMapper.selectByExample(elecStationOutExample);
        if (elecStationOuts != null && elecStationOuts.size() > 0) {
            //补全图片地址
            for (ElecStationOut elecStationOut : elecStationOuts) {
                elecStationOut.setOutImage1(elecStationOut.getOutImage1() != null ? upYunConfig.getDownloadRoot() + elecStationOut.getOutImage1() : "");
                elecStationOut.setOutImage2(elecStationOut.getOutImage2() != null ? upYunConfig.getDownloadRoot() + elecStationOut.getOutImage2() : "");
                elecStationOut.setOutImage3(elecStationOut.getOutImage3() != null ? upYunConfig.getDownloadRoot() + elecStationOut.getOutImage3() : "");
            }
            return elecStationOuts.get(0);
        } else {
            return null;
        }
    }
}
